/* @(#)UserDAOImpl.java v${project.version} 2011-6-16 下午03:28:28 
 * 
 * ${project.copyright.info}
 * ${project.copyright}
 * ==============================================================================================================*/
package net.lysa.ooo.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

import net.lysa.ooo.dao.UserDAO;

import org.springframework.stereotype.Repository;

import domain.Question;
import domain.User;

/**
 * <p>Class description goes here.</p>
 * 
 * @see    java.lang.Object
 * @author caochuan@guahaoe.com
 */
@Repository
public class UserDAOImpl implements UserDAO {
	@PersistenceContext
	private EntityManager em;
	
	public void save(User user) {
		em.persist(user);
	}
	
	public List<User> findAll(){
//		TypedQuery<User> query = em.createQuery("select user from User user",User.class);
		Query query = em.createQuery("select user from User user");
		//query.setFirstResult(1);
		//query.setMaxResults(10);
		return query.getResultList();
	}
	
	public User get(String id){
		return em.find(User.class, id);
	}
	
	public void delete(String id) {
		User user = em.find(User.class, id);
		em.remove(user);
	}
	
	public <X> List<X> findAll2(){
		return new ArrayList<X>();
	}

	@Override
	public void saveQuestion(Question question) {
		em.persist(question);
		
	}	

}
